#ifndef __JSON_PATH_TOKEN_H__
#define __JSON_PATH_TOKEN_H__

#include <string>

#include "JsonPathSquareBracket.h"

enum JsonPathTokenType
{
    JsonPathTokenType_Root,         //  $  根节点

    JsonPathTokenType_Dot,          //  .  子节点操作符
    JsonPathTokenType_SquareBracketL,//  [  下标操作符
    JsonPathTokenType_DotDot,       //  .. 递归下降

    JsonPathTokenType_Key,          //  key

    JsonPathTokenType_Max
};

class JsonPathToken
{
public:
    JsonPathToken() : m_eType(JsonPathTokenType_Max), m_pUserData(NULL) {}
    JsonPathToken(const JsonPathToken& stToken)
    {
        m_eType = stToken.m_eType;
        m_strTokenName = stToken.m_strTokenName;
        if (m_eType == JsonPathTokenType_SquareBracketL && stToken.m_pUserData != nullptr)
        {
            JsonPathSquareBracket* p = new JsonPathSquareBracket(*(JsonPathSquareBracket*)stToken.m_pUserData);
            m_pUserData = (void*)p;
        }
    }
    JsonPathToken& operator=(const JsonPathToken& stToken)
    {
        m_eType = stToken.m_eType;
        m_strTokenName = stToken.m_strTokenName;
        if (m_eType == JsonPathTokenType_SquareBracketL && stToken.m_pUserData != nullptr)
        {
            JsonPathSquareBracket* p = new JsonPathSquareBracket(*(JsonPathSquareBracket*)stToken.m_pUserData);
            m_pUserData = (void*)p;
        }
        return *this;
    }
    ~JsonPathToken()
    {
        if (m_eType == JsonPathTokenType_SquareBracketL && m_pUserData != nullptr)
        {
            delete (JsonPathSquareBracket*)m_pUserData;
            m_pUserData = nullptr;
        }
    }

public:
    JsonPathTokenType m_eType;
    std::string m_strTokenName;
    void* m_pUserData;
};

#endif // __JSON_PATH_TOKEN_H__
